#include "test.pb.h"
#include <iostream>
#include <string>

using namespace testProtoc;


int main()
{
    /*
    message GetFriendListsResponse
    {
        ResultCode result = 1;
        repeated User friend_list = 2;  // 定义了一个列表类型
    }
    */
    GetFriendListsRespone rsp;
    // 获取message GetFriendListsResponse{}里的ResultCode指针
    ResultCode* rc = rsp.mutable_result();
    rc->set_errcode(0);
    
    // 获取message GetFriendListsRespone{}里的列表添加方法
    User* user1 = rsp.add_friend_list();
    user1->set_name("wangzn2016");
    user1->set_age(22);
    user1->set_sex(User::MAN);

    User* user2 = rsp.add_friend_list();
    user2->set_name("wangzn20161");
    user2->set_age(22);
    user2->set_sex(User::WOMAN);

    // 获取message GetFriendListsResponse{}里的列表friend_list的大小
    std::cout << rsp.friend_list_size() << std::endl;  
    // 获取列表成员，User user = rsp.friend_list(int index);
    User user = rsp.friend_list(0);
    std::cout << user.name() << std::endl;
    return 0;
}

int main1()
{
    LoginRequest req;
    req.set_name("wangzn2016");
    req.set_pwd("123456");

    // 序列化
    std::string send_str;
    if (req.SerializeToString(&send_str)) {
        std::cout << send_str << std::endl;
    }

    // 反序列化
    LoginRequest praseReq;
    if (praseReq.ParseFromString(send_str)) {
        std::cout << praseReq.name() << std::endl;
        std::cout << praseReq.pwd() << std::endl;
    }
    return 0;
}
